<?php require_once '../yubiphpbase/appinclude.php';
require_once '../yubiphpbase/yubi_lib.php';
include 'head.htm';
$act = getHttpVal('act', -1);
$msg = getHttpVal('msg', '');
$notes = getHttpVal('notes', '');
$email = getHttpVal('email', '');
$client = getHttpVal('client', -1);

if (($usrid = getUsrIdFromSession()) <= 0) {
	echo TIMEDOUT;
	exit;
} else if (!isRootAdm() && $client != $_SESSION['client']) {
    echo ROOT_ONLY;
    exit;
}

$email = $_SESSION['email'];
$a = getClientInfo($client);
?>

<title>Yubikey Admin - Client Information</title>

<body>

<div align=left id="E" style=background:#eeeeee;>

<table border=0>

<tr><td align=center>
<?php
if (strlen($msg) > 0) {
	echo '<font color=red>'.$msg.'</font>';
}
?>
</td></tr>

<tr><td valign=top align=center colspan=2>
<h2>About Client-<?php echo $client;?></h2>
</td></tr>

<tr><td align=left>
<ul>
<li>The client owns <?php echo $a['num_active'].' active Yubikeys'; ?>
<li>The client owns <?php echo $a['num_inactive'].' inactive Yubikeys'; ?>
<li>Email: <?php echo $a['email'];?>
<li>API Key: <?php echo $a['secret'];?>
<li>Check validation signature? <?php echo ($a['chk_sig'] ? 'Yes' : 'No');?>
<li>Active? <?php echo ($a['active'] ? 'Yes' : 'No');?>
<li>Created: <?php echo $a['created'];?>
<li>Permission: <?php echo explainPerm($a['perm_id'])?>
<?php if (isRootAdm() && strlen($a['notes']) > 1) { ?>
<li>Notes: <?php echo $a['notes'];?>
<?php } ?>
</ul>
</td>

<td valign=top align=left>
<?php showBuyerInfo($client); ?>
</td>

</tr>

<tr><td colspan=2 align=left>
<?php showAdmKeys($client); ?>
<br><br><font color=#008080 size=2>
To update client information, go under the <b>Clients</b> tab in the console.
</td></tr>

<tr><td colspan=2 align=center>
<hr size=1 width=70%>
<img src=images/close.gif>
<A href="javascript:window.close();">Close this window</A>
</td></tr>
</table>

</table>

</div>

<?php
function showAdmKeys($client) {
  $stmt = 'SELECT a.note,a.last_access,a.pin,a.creation,y.active,y.tokenId FROM admin a, yubikeys y WHERE a.client='.$client.' AND a.keyid=y.id';
  $r = query($stmt);
  $n = mysql_num_rows($r);
  echo '<center><b>Client-'.$client.' has '.$n.' admin Yubikey(s)</b></center><p>';
  if ($n > 0) {
    echo '<table border=1><tr bgcolor=#ADFF2F><th>TokenId</th><th>Active</th><th>Password</th><th>Note</th><th>Last Access</th><th>Creation</th>';
    while ($row=mysql_fetch_assoc($r)) {
	echo '<tr><td>'.b64ToModhex($row['tokenId']).'</td><td>'.
		$row['active'].'</td><td>'.aesDecrypt($row['pin']).'</td><td>'.
		$row['note'].'</td><td>'.
		$row['last_access'].'</td><td>'.$row['creation'].
		'</td></tr>';
    }
    mysql_free_result($r);
    echo '</table>';
  }
}

function showBuyerInfo($client) {
  $stmt = 'SELECT * FROM buyers WHERE client_id='.$client;
  $r = query($stmt);
  $n = mysql_num_rows($r);
  if ($n > 0 && ($row=mysql_fetch_assoc($r))) {
    mysql_free_result($r);
    echo '<center><b>Shipping Record</b></center>';
	echo '<ul>';
	echo '<li>Buyer: '.$row['name'];
	echo '<li>Email: '.$row['email'];
	echo '<li>Address: '.$row['addr'];
	echo '</ul>';
  }
}
?>
